home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.2 / Bullet / spacing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  3.7 KB  |  172 lines

  1. #define  DEBUG
  2. #ifdef   DEBUG
  3. #define  D(a)    kprintf a
  4. #else
  5. #define  D(a)
  6. #endif
  7. #include <exec/types.h>
  8. #include <dos/rdargs.h>
  9. #include <graphics/rastport.h>
  10. #include <intuition/intuition.h>
  11.  
  12. #include <clib/exec_protos.h>
  13. #include <clib/dos_protos.h>
  14. #include <clib/graphics_protos.h>
  15. #include <clib/intuition_protos.h>
  16. #include <clib/diskfont_protos.h>
  17. #include <pragmas/exec_pragmas.h>
  18. #include <pragmas/dos_pragmas.h>
  19. #include <pragmas/graphics_pragmas.h>
  20. #include <pragmas/intuition_pragmas.h>
  21. #include <pragmas/diskfont_pragmas.h>
  22.  
  23. #include <string.h>
  24. #undef    strchr
  25. #undef    strcmp
  26. #undef    strcpy
  27. #undef    strrchr
  28. #undef    memset
  29.  
  30. extern struct Library *SysBase;
  31. extern struct Library *DOSBase;
  32.  
  33. #define  TEMPLATE    "NAME,TITLE"
  34.  
  35. #define  O_NAME        0
  36. #define  O_TITLE    1
  37. #define  O_COUNT    2
  38.  
  39. struct Library *GfxBase = 0;
  40. struct Library *IntuitionBase = 0;
  41. struct Library *DiskfontBase = 0;
  42. struct RDArgs *RDArgs = 0;
  43. struct TextFont *Font = 0;
  44.  
  45. #define  X2    640
  46. #define  Y2    400
  47. struct Window *Window = 0;
  48. struct IntuiMessage *IM;
  49.  
  50. void
  51. closeFont()
  52. {
  53.     if (Font)
  54.     CloseFont(Font);
  55.     Font = 0;
  56. }
  57.  
  58. void
  59. endGame(format, arg1, arg2, arg3, arg4)
  60. char *format, *arg1, *arg2, *arg3, *arg4;
  61. {
  62.     if (format) {
  63.     D((format, arg1, arg2, arg3, arg4));
  64.     printf(format, arg1, arg2, arg3, arg4);
  65.     }
  66.     if (Window)
  67.     CloseWindow(Window);
  68.     closeFont();
  69.     if (RDArgs)
  70.     FreeArgs(RDArgs);
  71.     if (DiskfontBase)
  72.     CloseLibrary(DiskfontBase);
  73.     if (IntuitionBase)
  74.     CloseLibrary(IntuitionBase);
  75.     if (GfxBase)
  76.     CloseLibrary(GfxBase);
  77.     if (format)
  78.     exit(5);
  79.     exit(0);
  80. }
  81.  
  82.  
  83. struct Window *
  84. myOpenWindowTags(tag)
  85. LONG tag;
  86. {
  87.     return (OpenWindowTagList(0, (struct TagItem *) & tag));
  88. }
  89.  
  90.  
  91. void
  92. main()
  93. {
  94.     ULONG *options[O_COUNT];
  95.     struct TextAttr textAttr;
  96.     int y;
  97.     char legend[128], *title;
  98.  
  99.     GfxBase = OpenLibrary("graphics.library", 0);
  100.     if (!GfxBase)
  101.     endGame("ERROR: cannot open \"graphics.library\"\n");
  102.     IntuitionBase = OpenLibrary("intuition.library", 0);
  103.     if (!IntuitionBase)
  104.     endGame("ERROR: cannot open \"intuition.library\"\n");
  105.     DiskfontBase = OpenLibrary("diskfont.library", 0);
  106.     if (!DiskfontBase)
  107.     endGame("ERROR: cannot open \"diskfont.library\"\n");
  108.  
  109.     memset(options, 0, sizeof(options));
  110.     RDArgs = ReadArgs(TEMPLATE, (LONG *) options, 0);
  111.     if (!RDArgs)
  112.     endGame("ERROR: invalid arguments\n");
  113.  
  114.     if (options[O_NAME])
  115.     textAttr.ta_Name = (char *) options[O_NAME];
  116.     else
  117.     textAttr.ta_Name = "CGTimes.font";
  118.     textAttr.ta_Flags = textAttr.ta_Style = 0;
  119.  
  120.     if (options[O_TITLE])
  121.     title = (char *) options[O_TITLE];
  122.     else
  123.     title = textAttr.ta_Name;
  124.  
  125.     Window = myOpenWindowTags(
  126.         WA_Left, 0,
  127.         WA_Top, 0,
  128.         WA_Width, X2,
  129.         WA_Height, Y2,
  130.         WA_IDCMP, CLOSEWINDOW,
  131.         WA_DepthGadget, TRUE,
  132.         WA_CloseGadget, TRUE,
  133.         WA_Title, title,
  134.         TAG_DONE);
  135.  
  136.     if (!Window)
  137.     endGame("OpenWindow failed\n");
  138.  
  139.     SetAPen(Window->RPort, 1);
  140.     SetDrMd(Window->RPort, JAM1);
  141.  
  142.     textAttr.ta_YSize = 4;
  143.     y = Window->BorderTop + 4;
  144.     while (y < Y2) {
  145.     textAttr.ta_YSize++;
  146.     Font = OpenDiskFont(&textAttr);
  147.     if (!Font)
  148.         endGame("OpenDiskFont %s %ld failed\n", textAttr.ta_Name,
  149.             textAttr.ta_YSize);
  150.  
  151.     SetFont(Window->RPort, Font);
  152.     Move(Window->RPort, 20, y);
  153.     sprintf(legend, "%3ld oo xx oxo hnh ijij aeiou 0123456789 qjy\305\264 "
  154.         "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ",
  155.         textAttr.ta_YSize);
  156.     Text(Window->RPort, legend, strlen(legend));
  157.     closeFont();
  158.     y += textAttr.ta_YSize + 1;
  159.     }
  160.  
  161.     /* wait until done before returning */
  162.     for (;;) {
  163.     while (IM = (struct IntuiMessage *) GetMsg(Window->UserPort)) {
  164.         if (IM->Class & CLOSEWINDOW) {
  165.         endGame(0);
  166.         }
  167.         ReplyMsg((struct Message *) IM);
  168.     }
  169.     WaitPort(Window->UserPort);
  170.     }
  171. }
  172.